package com.Ajava1704.for设计模式.for动态代理.CGLIB2;

import com.alibaba.fastjson.JSON;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 作者: LCG
 * 日期: 2020/6/27 23:04
 * 描述:
 */
public class TestDaiLi<T> implements MethodInterceptor {

    private Enhancer enhancer=new Enhancer();

    public T getByClass(Class classs){

        enhancer.setSuperclass(classs);

        enhancer.setCallback(this);

        return (T) enhancer.create();
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

        //method.invoke("传进来一个对象",objects);
        System.out.println(JSON.toJSONString(objects)+"------"+method.getName());
        return null;
    }
}
